package com.quan.upms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.quan.common.core.support.BaseService;
import com.quan.upms.entity.UpmsMenu;
import com.quan.upms.service.UpmsMenuService;
import com.quan.upms.service.UpmsPermissionService;

/**
 * <p>
 * 通用用户权限系统-菜单表 服务实现类
 * </p>
 *
 * @author 杨浩泉
 * @since 2018-05-13
 */
@Service
public class UpmsMenuServiceImpl extends BaseService<UpmsMenu> implements UpmsMenuService {
	
	@Autowired
	private UpmsPermissionService permissionService;
	
	@Override
	public int deleteById(Object id) {
		//删除管理菜单的权限
		this.permissionService.deletePermissionByMenuId(Integer.parseInt(id.toString()));
		
		return recursiveDelete(Integer.valueOf(id.toString()));
	}
	
	private int recursiveDelete(Integer id) {
		
		UpmsMenu entity = new UpmsMenu() ;
		entity.setPid(id);
		List<UpmsMenu> loadChildrenNode = super.selectAll(entity) ;
		if(null != loadChildrenNode) {
			for (UpmsMenu menu : loadChildrenNode) {
				recursiveDelete(menu.getId());
			}
		}
		return super.deleteById(id) ;
	}
	
}